WaitOnBlitImageThread
Status = WaitOnBlitImageThread()
 
Parameters: NONE
Returns:

    Status = The Status code of wait. 1=Waited, 0 = failed
 

     The WaitOnBlitImageThread functions forces our program to wait until any previously threaded blitimage task has completed it's work, allows us to safely synchronize the main program with our secondary thread running on another CPU core . The function returns 0 when it didn't need to wait (failed) and a 1 when it had needed to wait..

      When ever you use threading, then you should always call the WaitOnBlitImageThread function to make sure the thread has finished it's work. Don't assume that code that runs in parallel on your system (without wait), will operate the same on all computers, it won't ! So we always need to wait for our threads to complete. The most common usage of wait will be to synchronize our main program with the thread, where the main program is dependant upon the output of the thread. Either way, always wait !


      For more information on threading see BlitImageThreadMode




FACTS:


      * Threading is only supported on the BlitImage commands.

      * We recommend calling WaitOnBlitImageThread prior to calling END in programs that use threading. Since it's possible that our threaded job might fire up as our program is closing, which could cause a crash on exit. Same thing could occur if our program deletes an image a thread is using, while it's using it!. So some care is needed





Example:




 
Example Source: Download This Example
; Inlude the Blit Image functions
  #Include "BlitImage"
  
  
; Create an FX image the size of the screen
  Dim LightMap(2)
  LIghtMap(0)               =NewImage(GetScreenWidth(),GetScreenHeight(),2)
  LIghtMap(1)               =NewImage(GetScreenWidth(),GetScreenHeight(),2)
  
  FrontImage     =0
  BackImage     =1-FrontImage
  
  
; Create a second  FX image the size of the screen
; we'll be using to blend with our other image
  Backdrop=NewFXImage(GetScreenWidth(),GetScreenHeight())
  
; fill the backdrop with something so we can see it
  Tile=LoadNewFxImage("..\../Media/bg22.jpg")
  RenderToImage Backdrop
  TileImage Tile,0,0,false
  
  LightCol=$f08040
  
  QueueMode=true
  
; --------------------------------------------------------------
; --------------------------------------------------------------
; Start of Demo loop
; --------------------------------------------------------------
; --------------------------------------------------------------
  Do
     
   ; Set threading mode to capture.
   ; this allows us to capture the next two blit image functions to
   ; the interal 'to do' list, so both jobs can be done on the seperate thread.
     
     If QueueMode=true
        blitimagethreadmode 2
     Else
        blitimagethreadmode 0
        
     EndIf
   ; redirect all drawing to screen back buffer
     RenderToScreen
     
     ThisLIghtMap=LightMap(FrontImage)
     
   ; To do combined Blit (copy) our Image.  This
   ; version multiples the pixels in the blend
   ; image (MyImage) with the backdrop. So it's
   ; using the blend image as light map.
     BlitImageAlphaMultImage(BackDrop,0,0,ThisLightMap)
     
     
     RenderToImage ThisLightMap
     BlitImageClear(ThisLightMap,0,0,RGB(00,00,00))
     
     
     If QueueMode=true
        blitimagethreadmode 3
     EndIf
     
     RenderToScreen
     LockBuffer
     
     
   ; redirect all drawing to this image
     RenderToImage LightMap(BackImage)
     
     If LeftMouseButton()<>0 Then LightCol=RndRGB()
     
   ; draw a bunch fo circle shaped shaded polgons to represent the light
     Draw_Light(100,100,150,$445566)
     
     Draw_Light(MouseX(),MouseY(),250,LightCol)
     
     
     Draw_Light(300,200,150,$ff00000)
     
     Draw_Light(700,400,150,$445566)
     
     
     RenderToScreen
     
     UnLockBuffer
     
     
     SetCursor 0,0
     
     
   ; make pb wait until our thread queue is done.
     waitonblitimagethread()
     
   ; Display some information about what's going on
     Text 0,0 ,"Thread Queue Example (light Maps)"
     Text 0,20,"Left Mouse to change light colour"
     Text 0,40,"Threading:"+Str$(QueueMode)
     Text 0,60,FPS()
     
     FrontImage     =1-FrontIMage
     BackImage     =1-BackImage
     
   ; Press the spake to toggle threading on / off
     If SpaceKey()
        QueueMode=1-QueueMode
        FlushKeys
     EndIf
     
   ; flip the back buffer to the front, so the user can see it
     Sync
     
  Loop
  
  
  
; --------------------------------------------------------------
; --[ DRAW LIGHT ]----------------------------------------------
; --------------------------------------------------------------
  
Function Draw_Light(X#,y#,Radius,Colour=$ffffff)
  
  Colour2=RGBFade(Colour,5)
  
  Edges=12
  steps#=360.0/Edges
  InkMode 1+64
  For lp=0 To Edges-1
     Angle1#=lp*Steps#
     Angle2#=WrapAngle(Angle1#,Steps#)
     
     x1#=x#+CosRadius(angle1#,Radius)
     y1#=y#+SinRadius(angle1#,Radius)
     
     x2#=X#+CosRadius(angle2#,Radius)
     y2#=y#+SinRadius(angle2#,Radius)
     
     GouraudTri x1#,y1#,Colour2,x2#,y2#,Colour2,x#,y#,Colour
     
  Next
  InkMode 1
  
EndFunction
  
  
  
  
 
Related Info: :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com